import * as echarts from '../../../components/ec-canvas/echarts.min';
const {checkLogin} = require('../../../utils/util')
// import geoJson from '../../../geoJson/area.geo';
var timer=null
const selectorRouteDatas = [{
    id: 0,
    title: "培训专员",
    key: "industryName",
    type: "radiobox",
    items: []
  },
  {
    id: 1,
    title: "应届毕业生",
    key: "graduation",
    type: "radiobox",
    items: []
  },
  {
    id: 2,
    title: "初级",
    key: "level",
    type: "radiobox",
    items: [{
        id: 1,
        title: "初级",
        checked: true
      },
      {
        id: 2,
        title: "中级"
      },
      {
        id: 3,
        title: "高级"
      },
    ]
  },
  {
    id: 3,
    title: "全国",
    type: "radiobox",
    key: "provinceId",
    items: []
  },
  {
    id: 4,
    title: "办学层次",
    key: "typeName",
    type: 'radiobox',
    items: [{
      id: '',
      title: "不限",
      checked: true
    }, {
      id: '本科',
      title: "本科",
      checked: true
    }, {
      id: '专科（高职）',
      title: "专科（高职）",
    }],
  },
  {
    id: 5,
    title: "排序",
    key: "orderBy",
    type: 'radiobox',
    items: [{
        id: 0,
        title: "默认排序",
        checked: true
      }, {
        id: 'scoreDesc',
        title: "分数由高到低",
      },
      // {
      //   id: 'scoreAsc',
      //   title: "分数由低到高",
      // },
      // {
      //   id: 'hotDesc',
      //   title: "热度由高到低",
      // },
      // {
      //   id: 'workRateDesc',
      //   title: "就业率由高到低",
      // },
      // {
      //   id: 'upRateDesc',
      //   title: "国内升学率由高到底",
      // },
    ],
  },
  {
    id: 6,
    title: "类型",
    key: "type",
    type: "radiobox",
    items: [{
        id: '',
        title: "全部",
      },
      {
        id: '公办学校',
        title: "公办学校",
      }, {
        id: '民办学校',
        title: "民办学校",
      },
      {
        id: '中外合作办学',
        title: "中外合作办学",
      },
      {
        id: '内地港澳台合作办学',
        title: "内地港澳台合作办学",
      },
    ],
  },
  {
    id: 7,
    title: "特色",
    key: "label",
    type: "radiobox",
    items: [{
        id: '',
        title: "全部",
      },
      {
        id: 985,
        title: "985",
      }, {
        id: 211,
        title: "211",
      },
      {
        id: '双一流',
        title: "双一流",
      },
      {
        id: '教育部直属',
        title: "教育部直属",
      },
      {
        id: '中央部委',
        title: "中央部委",
      },
      {
        id: '双高计划',
        title: "双高计划",
      },
      {
        id: '强基计划',
        title: "强基计划",
      },
    ]
  },
  {
    id: 8,
    title: "全国",
    key: "province",
    type: "radiobox",
    items: []
  },
  {
    id: 9,
    title: "类型",
    key: "eduType",
    type: "radiobox",
    items: [{
        id: '',
        title: "全部",
      },
      {
        id: '公办学校',
        title: "公办学校",
      }, {
        id: '民办学校',
        title: "民办学校",
      },
      {
        id: '中外合作办学',
        title: "中外合作办学",
      },
      {
        id: '内地港澳台合作办学',
        title: "内地港澳台合作办学",
      },
    ],
  },
  {
    id: 10,
    title: "特色",
    key: "schoolLabel",
    type: "radiobox",
    items: [{
        id: '',
        title: "全部",
      },
      {
        id: 985,
        title: "985",
      }, {
        id: 211,
        title: "211",
      },
      {
        id: '双一流',
        title: "双一流",
      },
      {
        id: '教育部直属',
        title: "教育部直属",
      },
      {
        id: '中央部委',
        title: "中央部委",
      },
      {
        id: '双高计划',
        title: "双高计划",
      },
      {
        id: '强基计划',
        title: "强基计划",
      },
    ]
  },
]
const {
  recommendDetail,
  addVoluntary,
  addSpecialty,
  queryOpenMajorPage,
  industrydistri,
  postdistri,
  regionadistri,
  salaryGraduation,
  salaryList,
  salaryIndustry,
  videoPage,
  twoMajorList,
  voluntarySum
} = require('../../../api/api')
const {
  filterObj
} = require('../../../utils/util')
const {
  planVoluntaryPage
} = require('../../../api/ai')
const {
  decodeUserInfo
} = require('../../../api/login')

function setOption(chart) {
  const option = {
    geo: {
      map: 'china',
      left: '40%',
      top: 10,
      right: 10,
      bottom: 10,
      aspectScale: 0.75,
      label: {
        show: true,
      },
      regions: [{
          name: '南海诸岛',
          value: 0,
          itemStyle: {
            normal: {
              opacity: 0,
              label: {
                show: false
              }
            }
          },
          label: {
            color: '#ffffff'
          }
        },
        {
          name: '西北',
          value: 0,
          itemStyle: {
            areaColor: '#FFFAEB',
            color: '#FFFAEB',
          },
          label: {
            color: '#F9B95A'
          }
        },
        {
          name: '西南',
          value: 0,
          itemStyle: {
            areaColor: '#FCD392',
            color: '#FCD392',

          },
          label: {
            color: '#FFFAEB'
          }
        },
        {
          name: '华南',
          value: 0,
          itemStyle: {
            areaColor: '#F9B95A',
            color: '#F9B95A',

          },
          label: {
            color: '#FFE9C5'
          }
        },
        {
          name: '华中',
          value: 0,
          itemStyle: {
            areaColor: '#FFE9C5',
            color: '#FFE9C5',

          },
          label: {
            color: '#F9B95A'
          }
        },
        {
          name: '华东',
          value: 0,
          itemStyle: {
            areaColor: '#FCD392',
            color: '#FCD392',

          },
          label: {
            color: '#FFFAEB'
          }
        },
        {
          name: '华北',
          value: 0,
          itemStyle: {
            areaColor: '#F9B95A',
            color: '#F9B95A',

          },
          label: {
            color: '#FFFAEB'
          }
        },
        {
          name: '东北',
          value: 0,
          itemStyle: {
            areaColor: '#FFFAEB',
            color: '#FFFAEB',

          },
          label: {
            color: '#FCD392'
          }
        },
      ],
      roam: false,
      itemStyle: {
        borderWidth: 0,
      },
      emphasis: false
    }
  };
  chart.setOption(option);
}
const color = ['#82cd00', '#ff9100', '#ffd000', '#ec4724', '#524fe5', '#a4baff', '#cc7cbd', '#52b0ac', '#f4baac']

function setBarOption(chart) {
  const option = {
    backgroundColor: '#ffffff',
    grid: {
      left: 0,
      right: 0,
      top: 20,
      bottom: 20,
    },
    xAxis: {
      type: 'category',
      data: ['广东省', '北京市', '西南地区', '华东地区', '华中地区'],
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      splitLine: {
        show: false
      },
    },
    yAxis: {
      type: 'value',
      show: false
    },
    series: [{
        data: [{
          value: 100,
          itemStyle: {
            color: 'rgba(252,164,0,1)'
          },
          percent: 10
        }, {
          value: 200,
          itemStyle: {
            color: 'rgba(252,164,0,0.8)'
          },
          percent: 10
        }, {
          value: 230,
          itemStyle: {
            color: 'rgba(252,164,0,0.6)'
          },
          percent: 10
        }, {
          value: 100,
          itemStyle: {
            color: 'rgba(252,164,0,0.4)'
          },
          percent: 10
        }, {
          value: 80,
          itemStyle: {
            color: 'rgba(252,164,0,0.2)'
          },
          percent: 10
        }],
        type: 'bar',
        barWidth: 40,
        label: {
          show: true,
          formatter: '{@percent}',
          position: 'top',
          color: '#333'
        },
      },

    ]
  };
  chart.setOption(option);
}

function pieChartSel(charts) {
  const that = this;
  let index = 0;
  //默认选中
  charts.dispatchAction({
    type: 'highlight',
    seriesIndex: 0,
    dataIndex: 0,
  });
  //hover选中
  charts.on('mouseover', function (e) {
    if (e.dataIndex != index) {
      charts.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
        dataIndex: index,
      });
    }
  });
  charts.on('mouseout', function (e) {
    index = e.dataIndex;
    charts.dispatchAction({
      type: 'highlight',
      seriesIndex: 0,
      dataIndex: e.dataIndex,
    });
  });

  //点击选中
  charts.on("click", function (e) {
    if (e.dataIndex != index) {
      charts.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
        dataIndex: index,
      });
    }
    index = e.dataIndex;
    charts.dispatchAction({
      type: 'highlight',
      seriesIndex: 0,
      dataIndex: e.dataIndex,
    });
  });
}
// 签约流向饼图
function setPieoption(chart, data) {
  const option = {
    color: color,
    tooltip: {
      show: false
    },
    // legend: {
    //   top: '220',
    //   left: 8,
    //   data: data,
    //   itemWidth: 10,
    //   itemHeight: 10,
    //   itemGap: 20,
    //   show: true,
    //   icon: 'rect',
    //   selectedMode: false,
    //   formatter: function (name) {
    //     let tarValue
    //     for (let i = 0; i < data.length; i++) {
    //       if (data[i].name == name) {
    //         tarValue = data[i].value
    //       }
    //     }
    //     let p
    //     if (tarValue < 10) {
    //       p = tarValue + '%  '
    //     } else {
    //       p = tarValue + '%'
    //     }
    //     return `{a|${p}}\n{b|${name}}`
    //   },
    //   textStyle: {
    //     lineHeight: 14,
    //     rich: {
    //       a: {
    //         fontSize: 14,
    //       },
    //       b: {
    //         fontSize: 10
    //       },
    //     },
    //     padding: [14, 0, -2, 0], //[上、右、下、左]
    //   },
    // },
    series: [{
      name: 'Access From',
      type: 'pie',
      radius: ['56%', '76%'],
      center: ['50%', '52%'],
      avoidLabelOverlap: false,
      label: {
        show: false,
        position: 'center',
      },
      emphasis: {
        label: {
          show: true,
          fontSize: '20',
          fontWeight: '500',
          color: '#000',
          formatter: '{a|{d}%\n}{b|{b}}',
          padding: [10, 10],
          rich: {
            a: {
              fontSize: 20
            },
            b: {
              fontSize: 14
            }
          }
        }
      },
      labelLine: {
        show: false
      },

      data: data
    }]
  };
  chart.setOption(option);
  pieChartSel(chart)
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLogin:false,
    loading:true,
    pageNo: 1,
    pageSize: 10,
    pageNoO: 1,
    seeMore: false,
    isVideoTrue: false,
    ellipsis: true,
    details: {},
    id: 1,
    loding:true,
    pieData: [],
    color: color,
    bottomLift: getApp().globalData.bottomLift,
    currentList: ['概况', '就业', '薪资', '开设院校', '录取概率'],
    // queryOpenMajorPage: [],
    videoShow: 0,
    currentIndex: 0,
    tabIndex: 0,
    tabList: [{
      code: 'chong',
      text: '可冲击',
      shortText: '冲',
      color: '#fb4500',
      bg: '#ffe3d9',
      border: '2rpx solid #fb4500',
      number: 0
    }, {
      code: 'wen',
      text: '较稳妥',
      shortText: '稳',
      color: '#fb7700',
      bg: '#fff2e6',
      border: '2rpx solid #fb7700',
      number: 0
    }, {
      code: 'bao',
      text: '可保底',
      shortText: '保',
      color: '#8bce00',
      bg: '#f4fbe6',
      border: '2rpx solid #8bce00',
      number: 0
    }, {
      code: 'all',
      text: '全部',
      shortText: '',
      color: '#b3b3b3',
      bg: '#f2f2f2',
      border: '2rpx solid #f2f2f2',
      number: 0
    }],
    filterRouteKey: "majorDetailsFilters",
    selectedData: {
      provinceId: 0,
      typeName: '',
      province:0,
      level: 1,
      type: '',
      schoolLabel: '',
      label: '',
      orderBy: 0,
      // level2Name:0,
      eduType: '',
      graduation: '',
      industryName: '',
    },
    selectorRouteDatas: selectorRouteDatas,
    ec: {
      lazyLoad: true,
    },
    ecBar: {
      lazyLoad: true,
    },
    code: '050301',
    schoolSpecialtyId: 872,
    list3: [],
    list: [],
    total: 0,
    list1: [],
    list2: [],
    articleList: [],
    userCitys: {},
    school: {
      name: 'schoolName'
    },
    canvasHeight: 784,
    luquListTotal: 0,
    pageENo: 1,
    luquList: [
    
    ],
    currentIndexArray: [1, 0, 0, 0, 0],
    isVip: false,
    isSvip: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options)
    if (options.code) {
      this.setData({
        code: options.code,
        // schoolSpecialtyId: options.schoolSpecialtyId
      })
    }
    const {
      filterRouteKey,
      selectedData
    } = this.data
    // selectedData.provinceId = wx.getStorageSync('userCitys').code
    wx.setStorageSync(filterRouteKey, selectedData)
    this.setData({
      userCitys: wx.getStorageSync('userCitys'),
      selectedData,
    })
    this.getDetail()
    this.fetchCityAndCategory()
  },
  // timer() {
  //   var {
  //     percentage,
  //   } = this.data
  //   const _this = this
  //   timer = setInterval(function () {
  //     if(percentage>=100){
  //       percentage = 0
  //       clearInterval(timer)
  //     }else{
  //       percentage = percentage+1
  //     }
  //     _this.setData({
  //       percentage
  //     })
  //   },50)

  // },
  // 获取专业视频解读
  async getVideoPage() {
    const {
      details,
      pageNoO,
      pageSize
    } = this.data
    const parmas = {
      pageNo: pageNoO,
      pageSize: pageSize,
      specialId: details.specialId,
    }
    const {
      result
    } = await videoPage(parmas)
    this.setData({
      ['articleList[' + (pageNoO - 1) + ']']: result.records,
      // pageNoO: pageNoO + 1,
    })
  },
  // 获取薪资-列表
  async getList() {
    const {
      selectorRouteDatas
    } = this.data
    if (selectorRouteDatas[0].items.length > 0) {
      if (this.data.list2.length > 0) return
      this.getsalaryList()
    } else {
      this.getSalaryIndustry()
    }
  },
  onHide() {
    // clearInterval(timer)
  },
  async getsalaryList() {
    this.setData({
      loding:true,
      list2:[]
    })
    const {
      details,
      selectedData
    } = this.data
    const {
      industryName,
      graduation,
      level
    } = selectedData
    const parmas = {
      specialId: details.specialId,
      industryName,
      graduation,
      level,
    }
    const {
      result
    } = await salaryList(parmas)
    const data = result.map(e => {
      return {
        salary: e['salary' + (level + 1)],
        name: e.cityName
      }
    })
    data.sort((a, b) => {
      return (b.salary) - (a.salary)
    })
    let tmax = Math.max.apply(Math, data.map(e => {
      return e.salary
    }))
    this.setData({
      list2: data,
      tmax,
      loding:false
    })

  },
  // 获取薪资-行业类型筛选条件
  async getSalaryIndustry() {
    const {
      details,
      selectedData,
      filterRouteKey,
      selectorRouteDatas,
    } = this.data
    const {
      result
    } = await salaryIndustry(details.specialId)
    if (result.length > 0) {
      selectorRouteDatas[0].items = result.map((item, i) => {
        return {
          id: item,
          title: item
        }

      })
      selectorRouteDatas[0].title = result[0]
      selectedData['industryName'] = result[0]
      this.setData({
        selectorRouteDatas,
        selectedData
      })
      wx.setStorageSync(filterRouteKey, selectedData)
      this.filterKeyFunc()
      this.getSalaryGraduation()
    }else{
      this.setData({
        loding:false
      })
    }
  },
  // 获取薪资-毕业时间筛选条件
  async getSalaryGraduation() {
    const {
      details,
      selectedData,
      filterRouteKey,
      selectorRouteDatas,
    } = this.data
    const {
      result
    } = await salaryGraduation(details.specialId)
    if (result.length > 0) {
      selectorRouteDatas[1].items = result.map((item, i) => {
        return {
          id: item,
          title: item
        }
      })
      selectorRouteDatas[1].title = result[0]
      selectedData['graduation'] = result[0]
      this.setData({
        selectorRouteDatas,
        selectedData
      })
      wx.setStorageSync(filterRouteKey, selectedData)
      this.filterKeyFunc()
      this.getsalaryList(selectedData)
    }else{
      this.setData({
        loding:false
      })
    }
  },

  async fetchCityAndCategory() {
    const {
      type,
      selectorRouteDatas
    } = this.data
    const cityList = wx.getStorageSync('cityList') || await getApp().getCityList()
    const eduTypeList = wx.getStorageSync('edu_type') || await getApp().getDictData('edu_type')
    const schoolLabelList = wx.getStorageSync('school_label') || await getApp().getDictData('school_label')
    schoolLabelList.unshift({
      id: '',
      title: "全部",
    })
    eduTypeList.unshift({
      id: '',
      title: "全部",
    })
    cityList.unshift({
      id: 0,
      title: '全国',
      checked: true
    })
    selectorRouteDatas[3].items = cityList
    selectorRouteDatas[6].items = eduTypeList
    selectorRouteDatas[7].items = schoolLabelList
    selectorRouteDatas[8].items = cityList
    selectorRouteDatas[9].items = eduTypeList
    selectorRouteDatas[10].items = schoolLabelList
    this.setData({
      selectorRouteDatas
    })
    this.filterKeyFunc()
  },

  onLoadFunc() {
    this.setData({
      pageNo: 1,
      list: [],
      loading:true
    })
    this.getSchool()
  },
  async getDetail() {
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    const {
      code
    } = this.data
    const {
      result
    } = await recommendDetail(code)
    wx.hideLoading()
    // details.level1Name.indexOf('本科')>-1?details.N
    // result['keyWordsOptions'] = result.postgraduateDirection.split('、')
    result['keyWordsOptions'] = result.postgraduateDirection && result.postgraduateDirection.split('、')
    this.setData({
      details: result,
    })
    this.getVideoPage()
  },
  async getSchool() {
    const {
      pageNo,
      pageSize,
      details
    } = this.data
    let params = {
      pageNo,
      pageSize,
      specialId: details.specialId
    }
    const {
      filterRouteKey
    } = this.data
    const selectedData = wx.getStorageSync(filterRouteKey)
    let obj = wx.getStorageSync('school_label_obj')
    let newObj = {}
    if (selectedData.label) {
      newObj[obj[selectedData.label]] = 1
    }
    params.provinceId = selectedData.provinceId
    params.typeName = selectedData.typeName
    params.eduLevel = 2
    params.eduType = selectedData.type
    params.orderBy = selectedData.orderBy
    params = filterObj(Object.assign(params, newObj))
    // console.log(params)
    const {
      result
    } = await queryOpenMajorPage(params)
    // if (result.records.length == 0) {
    //   return
    // }
    result.records.map((item) => {
      item['isAddVolunteer'] = false
      item = Object.assign(item, item.school)
      item.schoolName = item.name
      let array = []
      if (item.isProject985 === 1) {
        array.push('985')
      }
      if (item.isProject211 === 1) {
        array.push('211')
      }
      if (item.isProject211 === 1 && item.isProject985 === 1) {
        array.push('双一流')
      }
      if (item.isStrongPlan === 1) {
        array.push('强基计划')
      }
      if (item.isDoubleHighPlan === 1) {
        array.push('双高计划')
      }
      if (item.schoolLevelName) {
        item.schoolLevelName = item.schoolLevelName.split(',')
        array = array.concat(item.schoolLevelName)
      }
      item['filter'] = array

    })

    this.setData({
      ['list[' + (pageNo - 1) + ']']: result.records,
      // pageNo: pageNo + 1,
      total: result.total,
      loading:false
    })
  },
  getSeeMore() {
    const that = this
    const query = wx.createSelectorQuery();
    query.selectAll('.seeMore').fields({
      size: true,
    }).exec(function (res) {
      if (res[0][0].height > 160) {
        that.setData({
          seeMore1: true,
        })
      }
      if (res[0][1].height > 160) {
        that.setData({
          seeMore2: true,
        })
      }
      if (res[0][2].height > 160) {
        that.setData({
          seeMore3: true,
        })
      }
    })
  },
  filterKeyFunc() {
    const {
      filterRouteKey
    } = this.data
    const selectedData = wx.getStorageSync(filterRouteKey)
    const {
      selectorRouteDatas
    } = this.data
    selectorRouteDatas.map((item) => {
      const c = item.items.filter((child) => {
        return child.id == selectedData[item.key]
      })
      // item.title = c.length > 0 ? c[0].title == '不限' ? '办学层次' : c[0].title : item.title
      item.title = c.length > 0 ? c[0].title == '不限' ? '办学层次' : (item.key == 'eduType' || item.key == 'type') && c[0].title == '全部' ? '类型' :
        (item.key == 'schoolLabel' || item.key == 'label') && c[0].title == '全部' ? '特色' : item.key == 'orderBy' ? '排序' : item.key == 'level2Name' && c[0].title == '全部' ? '专业' : c[0].title : item.title

    })
    this.setData({
      selectorRouteDatas,
      selectedData
    })
  },
  async onSelectChangedRoute(e) {
    const {
      currentIndex
    } = this.data
    const {
      filterRouteKey
    } = this.data
    wx.setStorageSync(filterRouteKey, {
      ...e.detail
    });
    this.filterKeyFunc()
    this.setData({
      ...e.detail
    });
    if (currentIndex == 2) {
      this.getsalaryList()
    } else if (currentIndex == 3) {
      this.onLoadFunc()
    } else if (currentIndex == 4) {
      checkLogin().then(res=>{
        this.refreshEnrollmentList()
        this.setData({
          isLogin:true
        })
      }).catch(e=>{
        this.setData({
          isLogin:false
        })
      })
    }

  },
  changeIndex(e) {
    const {
      index,
    } = e.currentTarget.dataset
    const {
      currentIndexArray,
      currentIndex,
    } = this.data
    if (index == currentIndex) return
    this.setData({
      currentIndex: parseInt(index),
    })
    if (currentIndexArray[parseInt(index)] > 0) return
    if (index == 1) {
      this.getDistri()
    } else if (index == 2) {
      this.getList()
    } else if (index == 3) {
      if (this.data.total) return
      this.onLoadFunc()
    } else if (index === 4) {
      checkLogin().then(res=>{
        this.refreshEnrollmentList()
        this.setData({
          isLogin:true
        })
      }).catch(e=>{
        this.setData({
          isLogin:false
        })
      })
    }
    currentIndexArray[parseInt(index)] += 1
    this.setData({
      currentIndexArray
    })
  },
  changeTab(e) {
    const {
      index,
    } = e.currentTarget.dataset
    if (index == this.data.tabIndex) return
    this.setData({
      tabIndex: parseInt(index),
    })
    // this.voluntarySum()
    this.setData({
      pageENo: 1,
      luquList: []
    })
    this.getEnrollmentList()
  },
  onShow() {
    this.fetchUserInfo()
  },
  async refreshEnrollmentList() {
    this.setData({
      pageENo: 1,
      luquList: []
    })
    // await this.voluntarySum()
    this.getEnrollmentList()
  },
  async getEnrollmentList() {
    this.setData({
      loading:true
    })
    let {
      id,
      pageSize,
      pageENo,
      isVip,
      code,
      tabList,
      tabIndex,
      filterRouteKey,details
    } = this.data
    let params = {
      // active: tabList[tabIndex].code,
      sptitle: details.name,
      // pageNo: pageENo,
      // pageSize: isVip ? pageSize : 3,
      // showAll:true,
    }
    const selectedData = wx.getStorageSync(filterRouteKey)
    let obj = wx.getStorageSync('school_label_obj')
    let newObj = {}
    if (obj[selectedData.schoolLabel]) {
      newObj[obj[selectedData.schoolLabel]] = 1
    }
    params.provinceId = selectedData.province
    params.eduType = selectedData.eduType
    params.specialtyIds = []
    // if (selectedData.level2Name) {
    //   params.specialtyIds=[selectedData.level2Name]
    // }
    params = filterObj(Object.assign(params, newObj))
    const {
      result
    } = await planVoluntaryPage(params)
    this.setData({
      // luquList: this.data.luquList.concat(result.records),
      luquList: isVip?result.records:result.records.slice(0,3),
      pageENo: this.data.pageENo + 1,
      luquListTotal: result.total,
    })
    if (result.total > 0) {
      var luquRatio = this.data.luquList[0].matchRate
      if (luquRatio >= 0.66) {
        luquRatio = '&gt;66%'
      } else if (luquRatio >= 0.49) {
        luquRatio = '&lt;66%'
      } else if (luquRatio >= 0.1) {
        luquRatio = '&lt;49%'
      } else {
        luquRatio = '&lt;10%'
      }
      this.setData({
        luquRatio,
      })
    } else {
      this.setData({
        luquRatio: "&lt;10%",
      })
    }
      this.setData({
        loading: false
      })
  },
  //  获取-录取概率
  // async getEnrollmentList(params) {

  // },
  async voluntarySum() {
    let {
      id,
      pageSize,
      pageENo,
      isVip,
      code,
      tabIndex,
      filterRouteKey,
      tabList
    } = this.data
    let params = {
      spcode: code,
      showAll:true,
    }
    const selectedData = wx.getStorageSync(filterRouteKey)
    let obj = wx.getStorageSync('school_label_obj')
    let newObj = {}
    if (obj[selectedData.schoolLabel]) {
      newObj[obj[selectedData.schoolLabel]] = 1
    }
    params.provinceId = selectedData.province
    params.eduType = selectedData.eduType
    params.specialtyIds = []
    // if (selectedData.level2Name) {
    //   params.specialtyIds=[selectedData.level2Name]
    // }
    params = filterObj(Object.assign(params, newObj))
    const {
      result
    } = await voluntarySum(params)
    tabList[0].number = result.chongCount
    tabList[1].number = result.wenCount
    tabList[2].number = result.baoCount
    tabList[3].number = result.allCount
    this.setData({
      tabList
    })
  },

  async fetchUserInfo() {
    const {vipType}= await getApp().fetchUserInfo()
    this.setData({
       isVip:vipType,
   })
  },
  getDistri() {
    const {
      specialId
    } = this.data.details
    this.getIndustrydistri(specialId)
    this.getPostdistri(specialId)
    this.getRegionadistri(specialId)
  },
  // 就业行业分布
  async getIndustrydistri(id) {
    const {
      list1
    } = this.data
    if (list1.length > 0) return
    const {
      result
    } = await industrydistri(id)
    let max = Math.max.apply(Math, result.map(e => {
      return e.rate
    }))
    this.setData({
      list1: result,
      max
    })

  },
  // 就业岗位分布
  async getPostdistri(id) {
    const {
      list3
    } = this.data
    if (list3.length > 0) return
    const {
      result
    } = await postdistri(id)
    let omax = Math.max.apply(Math, result.map(e => {
      return e.rate
    }))
    this.setData({
      list3: result,
      omax
    })
  },
  // 就业地区分布
  async getRegionadistri(id) {
    const {
      pieData
    } = this.data
    if (pieData.length > 0) return
    const {
      result
    } = await regionadistri(id)
    const data = result.map(e => {
      return {
        name: e.area,
        value: e.rate
      }
    })
    data.sort((a, b) => b.value - a.value)
    this.setData({
      pieData: data
    })
    if (data.length <= 0) return
    this.initChart(data);
  },
  makePhone(e) {
    const {
      phone
    } = e.currentTarget.dataset
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },
  // 复制链接
  textPaste(e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success(res) {
        wx.showToast({
          title: '地址复制成功',
          icon: 'none'
        })
      }
    })
  },
  // 收藏专业
  async collect(e) {
    const {
      code
    } = e.currentTarget.dataset
    const {
      details
    } = this.data
    var result = await addSpecialty(details.code)
    details.isCollection = !details.isCollection
    this.setData({
      details
    })
    if (!details.isCollection) return
    wx.showToast({
      title: result.message,
      icon: "none"
    })
  },
  async schoolcollect(e) {
    const {
      schoolSpecialtyId,
      details
    } = this.data
    var result = await addVoluntary(schoolSpecialtyId)
    details.isCollection = !details.isCollection
    this.setData({
      details
    })
    if (!details.isCollection) return
    wx.showToast({
      title: result.message,
      icon: "none"
    })
  },
  async addVolunteer(e) {
    const {
      id,
      list
    } = e.detail
    this.setData({
      list
    })
  },
  //取消志愿
  async deleteVolunteer(e) {
    const {
      id,
      list
    } = e.detail
    this.setData({
      list
    })
  },
  //预览

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // this.ecComponent = this.selectComponent('#mychart-dom-area');
    // this.barComponent = this.selectComponent('#mychart-bar');
    // this.initChart();
  },
  initChart(pieData) {
    this.ecComponent = this.selectComponent('#mychart-dom-area');
    this.ecComponent.init((canvas, width, height, dpr) => {
      const chart = echarts.init(canvas, null, {
        width: width,
        height: height,
        devicePixelRatio: dpr, // new
      });
      // 注册中国地图数据包
      // echarts.registerMap('china', geoJson);
      // 设置数据
      setPieoption(chart, pieData);
      // 将图表实例绑定到 this 上，可以在其他成员函数（如 dispose）中访问
      this.chart = chart;
      return chart;
    });
    return
    this.barComponent.init((canvas, width, height, dpr) => {
      const chart = echarts.init(canvas, null, {
        width: width,
        height: height,
        devicePixelRatio: dpr, // new
      });
      // 设置数据
      setBarOption(chart);
      this.chart = chart;
      return chart;
    });
  },


  onShareAppMessage: function () {
    const {
      details,
      code
    } = this.data
    return {
      title: details.name,
      imageUrl: 'https://ehsimg.oss-cn-beijing.aliyuncs.com/images/static/users/shareImg.jpg',
      path: `/pages/major/detail/index?code=${code}`
    }
  },
  onReachBottom() {
    const {
      currentIndex,
      pageNo,
      articleList,
      pageNoO,
      pageSize,
      list,
      luquListTotal,
      isVip,
      luquList
    } = this.data
    if (currentIndex == 0) {
      const length = articleList[pageNoO - 1].length
      if (length >= pageSize) {
        this.setData({
          pageNoO: pageNoO + 1
        })
        this.getVideoPage()
      }
    }
    if (currentIndex == 3) {
      const length = list[pageNo - 1].length
      if (length >= pageSize) {
        this.setData({
          pageNo: pageNo + 1
        })
        this.getSchool()
      }
    }
    if (currentIndex == 4) {
      const count = luquList.length
      if (count == luquListTotal || count == 0 || !isVip) return
      // this.getEnrollmentList()
    }

  },
  ellipsis(e) {
    this.setData({
      ellipsis: !this.data.ellipsis
    })
  },

  goto(e) {
    const {
      url
    } = e.currentTarget.dataset
    wx.navigateTo({
      url
    })
  },
  showMore(e) {
    const {
      type
    } = e.currentTarget.dataset
    this.setData({
      [type]: !this.data[type]
    })
  },

})
